package com.joysuch.wwyt.common.controller;

import com.joysuch.wwyt.bp.bean.inspect.BpInpectUserDto;
import com.joysuch.wwyt.bp.bean.inspect.BpInspectFinishRateDto;
import com.joysuch.wwyt.bp.bean.inspect.BpInspectTaskFinishDto;
import com.joysuch.wwyt.bp.bean.safetyworkcert.*;
import com.joysuch.wwyt.bp.service.BpInspectRecordService;
import com.joysuch.wwyt.bp.service.BpWorkSafetyCertService;
import com.joysuch.wwyt.common.bean.CommonStaticsReportBean;
import com.joysuch.wwyt.common.service.CommonStaticsReportService;
import com.joysuch.wwyt.core.common.ajax.ResultBean;
import com.joysuch.wwyt.edu.bean.EduCourseCountDto;
import com.joysuch.wwyt.edu.bean.EduExamCountDto;
import com.joysuch.wwyt.edu.bean.EduExamReleaseDto;
import com.joysuch.wwyt.edu.service.EduCourseService;
import com.joysuch.wwyt.edu.service.EduCourseStatisticsService;
import com.joysuch.wwyt.edu.service.EduExamService;
import com.joysuch.wwyt.edu.service.EduTrainningPlanService;
import com.joysuch.wwyt.mh.service.MhAlarmMessageService;
import com.joysuch.wwyt.risk.service.RiskDistrictService;
import com.joysuch.wwyt.risk.service.RiskPointService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.time.LocalDateTime;

/**
 * @Author ZhangDong
 * @Date 2020/7/23 14:06
 */
@RestController
@RequestMapping("/common/statics/report")
@Api(tags = "/common/statics/report 统计报表")
public class CommonStaticsReportController {

    @Autowired
    private CommonStaticsReportService commonStaticsReportService;
    @Autowired
    private MhAlarmMessageService mhAlarmMessageService;
    @Autowired
    private EduExamService eduExamService;
    @Autowired
    private EduCourseStatisticsService eduCourseStatisticsService;
    @Autowired
    private EduTrainningPlanService eduTrainningPlanService;
    @Autowired
    private BpInspectRecordService bpInspectRecordService;
    @Autowired
    private BpWorkSafetyCertService bpWorkSafetyCertService;
    @Autowired
    private EduCourseService eduCourseService;
    @Autowired
    private RiskDistrictService riskDistrictService;
    @Autowired
    private RiskPointService riskPointService;

    @PostMapping("save")
    @RequiresPermissions("common:statics:report:save")
    @ApiOperation("新增/修改统计页")
    public ResultBean save(@RequestBody @Valid CommonStaticsReportBean bean) {
        return commonStaticsReportService.save(bean);
    }

    @PostMapping("delete")
    @RequiresPermissions("common:statics:report:delete")
    @ApiOperation("删除统计页")
    public ResultBean delete(Long id) {
        return commonStaticsReportService.delete(id);
    }

    @GetMapping("list")
    @ApiOperation(value = "查询所有统计页", response = CommonStaticsReportBean.class)
    public ResultBean list() {
        return commonStaticsReportService.list();
    }

    @GetMapping("get")
    @ApiOperation(value = "查询单个统计页", response = CommonStaticsReportBean.class)
    public ResultBean get(Long id) {
        return commonStaticsReportService.get(id);
    }

    /**
     * 教育模块统计
     * 考试发布数量统计:本年度每个月新发布的考试数量统计-柱状图
     */
    @GetMapping("edu-exam-join-rate")
    @ApiOperation(value = "教育-1考试参与率统计", response = BpWorkApplyDto.class)
    public ResultBean eduExamJoinRate() {
        return eduCourseStatisticsService.eduExamJoinRate();
    }

    @GetMapping("edu-exam-pass-rate")
    @ApiOperation(value = "教育-2考试合格率统计", response = EduExamCountDto.class)
    public ResultBean eduExamPassRate() {
        return eduCourseStatisticsService.examStatistics();
    }

    @GetMapping("edu-exam-release")
    @ApiOperation(value = "教育-4考试发布数量统计", response = EduExamReleaseDto.class)
    public ResultBean eduExamRelease() {
        return eduExamService.eduExamRelease();
    }

    @GetMapping("edu-course")
    @ApiOperation(value = "教育-6课程占比统计", response = EduCourseCountDto.class)
    public ResultBean eduCourse(){ return eduCourseService.eduCourse(); }

    @GetMapping("edu-train-query")
    @ApiOperation(value = "教育-8培训发布统计", response = EduExamReleaseDto.class)
    public ResultBean eduTrainQuery() {
        return eduTrainningPlanService.eduTrainQuery();
    }

    /**
     * 巡检模块统计
     * 异常统计:30天 每日发现的异常统计
     */
    @GetMapping("inspect-finish-rate")
    @ApiOperation(value = "巡检-1完成率统计", response = BpInspectTaskFinishDto.class)
    public ResultBean inspectFinishRate(){ return bpInspectRecordService.inspectFinishRate(); }

    @GetMapping("inspect-exception-query")
    @ApiOperation(value = "巡检-2异常统计", response = EduExamReleaseDto.class)
    public ResultBean inspectExceptionQuery() { return bpInspectRecordService.inspectExceptionQuery(); }

    @GetMapping("inspect-exception-route-query")
    @ApiOperation(value = "巡检-3异常巡检路线统计", response = EduExamReleaseDto.class)
    public ResultBean inspectExceptionRouteQuery() { return bpInspectRecordService.inspectExceptionRouteQuery(); }

    @GetMapping("inspect-exception-point")
    @ApiOperation(value = "巡检-4异常检查点统计", response = EduExamReleaseDto.class)
    public ResultBean inspectExceptionPoint() { return bpInspectRecordService.inspectExceptionPoint(); }

    @GetMapping("inspect-user-query")
    @ApiOperation(value = "巡检-5人员统计", response = BpInpectUserDto.class)
    public ResultBean inspectUserQuery(){ return bpInspectRecordService.inspectUserQuery(); }

    @GetMapping("inspect-today-finish")
    @ApiOperation(value = "巡检-6今日完成率", response = BpInspectFinishRateDto.class)
    public ResultBean inspectTodayFinish() {
        return bpInspectRecordService.inspectTodayFinish();
    }

    @GetMapping("inspect-today-exception")
    @ApiOperation(value = "巡检-7今日异常率", response = BpInspectFinishRateDto.class)
    public ResultBean inspectTodayException() {
        return bpInspectRecordService.inspectTodayException();
    }

    /**
     * 作业模块统计
     *
     */
    @GetMapping("work-30-recent")
    @ApiOperation(value = "作业-1最近30天作业数量", response = BpWork30RecentDto.class)
    public ResultBean work30Recent(){ return bpWorkSafetyCertService.work30Recent(); }

    @GetMapping("work-today")
    @ApiOperation(value = "作业-2今日作业统计", response = BpWorkTodayDto.class)
    public ResultBean workToday(){ return bpWorkSafetyCertService.workToday(); }

    @GetMapping("work-audit-pass")
    @ApiOperation(value = "作业-3审批通过率统计", response = BpWorkApplyDto.class)
    public ResultBean workAuditPass(){ return bpWorkSafetyCertService.workAuditPass(); }

    @GetMapping("work-check-pass")
    @ApiOperation(value = "作业-4验收合格率统计", response = BpWorkApplyDto.class)
    public ResultBean workCheckPass(){ return bpWorkSafetyCertService.workCheckPass(); }

    @GetMapping("work-apply")
    @ApiOperation(value = "作业-5申请单位统计", response = BpWorkApplyDto.class)
    public ResultBean workApply(){ return bpWorkSafetyCertService.workApply(); }

    @GetMapping("work-area")
    @ApiOperation(value = "作业-6区域统计", response = BpWorkRiskDto.class)
    public ResultBean workArea(){ return bpWorkSafetyCertService.workArea(); }

    @GetMapping("work-risk")
    @ApiOperation(value = "作业-7风险统计", response = BpWorkRiskDto.class)
    public ResultBean workRisk(){ return bpWorkSafetyCertService.workRisk(); }

    @GetMapping("work-time-scope")
    @ApiOperation(value = "作业-8作业时段统计")
    public ResultBean workTimeScope(){ return bpWorkSafetyCertService.workTimeScope(); }

    @GetMapping("work-prescription")
    @ApiOperation(value = "作业-9完成时效统计", response = BpWorkStaticsDto.class)
    public ResultBean workPrescription(){ return bpWorkSafetyCertService.workPrescription(); }

    /**
     * 风险分区模块统计
     */
    @GetMapping("risk-area-sum")
    @ApiOperation(value = "风险分区-4个风险等级的区域数量占比", response = BpWorkRiskDto.class)
    public ResultBean riskAreaSum(){
        return riskDistrictService.riskAreaSum();
    }

    @GetMapping("risk-area-point")
    @ApiOperation(value = "风险分区-不同区域的风险点数量占比", response = BpWorkRiskDto.class)
    public ResultBean riskAreaPoint(){
        return riskPointService.riskAreaPoint();
    }


    @GetMapping("harzard-query")
    @ApiOperation("重大危险源检测报警统计")
    public ResultBean harzardQuery(LocalDateTime startTime, LocalDateTime endTime) {
        return mhAlarmMessageService.harzardQuery(startTime, endTime);
    }

}
